class Queue {
  constructor() {
      this.count = 0
      this.lowestCount = 0
      this.items = {}
  }

  // 入队
  enqueue(element) {
      this.items[this.count] = element
      this.count++
  }
  // 出队
  dequeue() {
      if (this.isEmpty()) {
          return undefined
      }
      const result = this.items[this.lowestCount]
      delete this.items[this.lowestCount]
      this.lowestCount++
      return result
  }
  // 对首元素
  peek() {
      if (this.isEmpty()) {
          return undefined
      }

      return this.items[this.lowestCount]
  }
  // 判空
  isEmpty() {
      return this.count === 0
  }
  // 清空
  clear() {
      this.items = {}
      this.count = 0
      this.lowestCount = 0
  }
  // 大小
  size() {
      return this.count - this.lowestCount
  }
  //转成字符串
  toString() {
      if (this.isEmpty()) {
          return ''
      }

      let objString = `${this.items[this.lowestCount]}`
      for (let i = this.lowestCount + 1; i < this.count; i++) {
          objString = `${objString}, ${this.items[i]}`
      }
      return objString
  }
}

const log = console.log.bind(console)
let queque = new Queue()
queque.enqueue('aaaa')
queque.enqueue('bbbb')
queque.enqueue('cccc')
queque.enqueue('dddd')
let item = queque.peek()
log(item, 'item')
queque.dequeue()
item = queque.peek()
log(item, 'item')
log(queque.lowestCount)
log(queque, 'queque')
// export default Queue